package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.FileUpload;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZhcaMyreportVo;
import com.ruoyi.system.bo.ZhcaMyreportQueryBo;
import com.ruoyi.system.bo.ZhcaMyreportAddBo;
import com.ruoyi.system.bo.ZhcaMyreportEditBo;
import com.ruoyi.system.service.IZhcaMyreportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;

/**
 * 上报管理Controller
 *
 * @author huaqihao
 * @date 2021-07-31
 */
@Validated
@Api(value = "上报管理控制器", tags = {"上报管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/myreport")
public class ZhcaMyreportController extends BaseController {

    private final IZhcaMyreportService iZhcaMyreportService;

    /**
     * 查询上报管理列表
     */
    @ApiOperation("查询上报管理列表")
    //@PreAuthorize("@ss.hasPermi('system:myreport:list')")
    @GetMapping("/list")
    public TableDataInfo<ZhcaMyreportVo> list(@Validated ZhcaMyreportQueryBo bo) {
        return iZhcaMyreportService.queryPageList(bo);
    }

    /**
     * 导出上报管理列表
     */
    @ApiOperation("导出上报管理列表")
	//@PreAuthorize("@ss.hasPermi('system:myreport:export')")
    @Log(title = "上报管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZhcaMyreportVo> export(@Validated ZhcaMyreportQueryBo bo) {
        List<ZhcaMyreportVo> list = iZhcaMyreportService.queryList(bo);
        ExcelUtil<ZhcaMyreportVo> util = new ExcelUtil<ZhcaMyreportVo>(ZhcaMyreportVo.class);
        return util.exportExcel(list, "上报管理");
    }

    /**
     * 获取上报管理详细信息
     */
    @ApiOperation("获取上报管理详细信息")
	//@PreAuthorize("@ss.hasPermi('system:myreport:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZhcaMyreportVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZhcaMyreportService.queryById(id));
    }

    /**
     * 新增上报管理
     */
    @ApiOperation("新增上报管理")
	//@PreAuthorize("@ss.hasPermi('system:myreport:add')")
    @Log(title = "上报管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZhcaMyreportAddBo bo) {
        return toAjax(iZhcaMyreportService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改上报管理
     */
    @ApiOperation("修改上报管理")
	//@PreAuthorize("@ss.hasPermi('system:myreport:edit')")
    @Log(title = "上报管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZhcaMyreportEditBo bo) {
        return toAjax(iZhcaMyreportService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除上报管理
     */
    @ApiOperation("删除上报管理")
	//@PreAuthorize("@ss.hasPermi('system:myreport:remove')")
    @Log(title = "上报管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZhcaMyreportService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }



	/**
	 * 上传图片
	 * @param file
	 * @return
	 * @throws Exception
	 */
	@ApiOperation("上传图片")
	@RequestMapping("/addup")
	@ResponseBody
	public String add(@RequestParam(name = "file") MultipartFile file) throws Exception {
		FileUpload fileUpload = new FileUpload();
		String pic1url = fileUpload.upload(file);
		return pic1url;
	}
}
